#pragma once
#include"RBtree.h"

namespace Map {
	template<class K,class V>
	class map {
		
		class KeyOfT {
		public:
			const K& operator()(const pair<K, V>& kv) {
				return kv.first;
			}

		};

	public:
		typedef typename RBtree<K, pair<const K, V>, KeyOfT>::iterator iterator;
		typedef typename RBtree<K, pair<const K, V>, KeyOfT>::const_iterator const_iterator;

	public:
		iterator begin() {
			return _tree.begin();
		}

		iterator end() {
			return _tree.end();
		}

		const_iterator begin()const {
			return _tree.begin();
		}

		pair<iterator, bool> Insert(const pair<K, V>& kv) {
			return _tree.Insert(kv);
		}

		V& operator[](const K& key) {
			pair<iterator, bool> ret = Insert(make_pair(key, V()));
			return  ret.first->second;
		}

	protected:
		RBtree<K, pair<const K, V>, KeyOfT> _tree;
	};

}